/**
 *====================================================
 * 文件名称: FinanceClaimActionApiImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年12月10日			chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.action.v1;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.BooleanUtils;

import com.yuexunit.core.BusinessException;
import com.yuexunit.core.ConfigPropertites;
import com.yuexunit.finance.common.util.BeanUtils;
import com.yuexunit.finance.common.util.CollectionUtils;
import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.context.FinanceBaseAction;
import com.yuexunit.finance.context.FinanceLetterBlockingQueue;
import com.yuexunit.finance.project.action.v1.dto.FinanceClaimCastor;
import com.yuexunit.finance.project.action.v1.dto.FinanceLoanCastor;
import com.yuexunit.finance.project.action.v1.model.ClaimAcceptance;
import com.yuexunit.finance.project.action.v1.model.ClaimAssessment;
import com.yuexunit.finance.project.action.v1.model.ClaimCorrective;
import com.yuexunit.finance.project.action.v1.model.ClaimHandle;
import com.yuexunit.finance.project.action.v1.model.ClaimMaterial;
import com.yuexunit.finance.project.action.v1.model.ClaimReportCase;
import com.yuexunit.finance.project.action.v1.model.ClaimSurvey;
import com.yuexunit.finance.project.action.v1.model.input.ClaimParams;
import com.yuexunit.finance.project.action.v1.model.input.ClaimSettlementParams;
import com.yuexunit.finance.project.action.v1.model.output.ClaimAcceptanceDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimAssessmentDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimCorrectiveDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimHandleDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimLineInfo;
import com.yuexunit.finance.project.action.v1.model.output.ClaimMaterialDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimReportCaseDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimSettlementDetail;
import com.yuexunit.finance.project.action.v1.model.output.ClaimSurveyDetail;
import com.yuexunit.finance.project.entity.AbnormalEntity;
import com.yuexunit.finance.project.entity.ClaimAcceptanceEntity;
import com.yuexunit.finance.project.entity.ClaimAssessmentEntity;
import com.yuexunit.finance.project.entity.ClaimCorrectiveEntity;
import com.yuexunit.finance.project.entity.ClaimCoverageEntity;
import com.yuexunit.finance.project.entity.ClaimEntity;
import com.yuexunit.finance.project.entity.ClaimHandleEntity;
import com.yuexunit.finance.project.entity.ClaimMaterialEntity;
import com.yuexunit.finance.project.entity.ClaimReportCaseEntity;
import com.yuexunit.finance.project.entity.ClaimSettlementCoverageEntity;
import com.yuexunit.finance.project.entity.ClaimSettlementEntity;
import com.yuexunit.finance.project.entity.ClaimSurveyEntity;
import com.yuexunit.finance.project.entity.FinanceMoneyStatementEntity;
import com.yuexunit.finance.project.entity.InsuranceEntity;
import com.yuexunit.finance.project.entity.lexicon.AbnormalStateEnum;
import com.yuexunit.finance.project.entity.lexicon.ClaimStateEnum;
import com.yuexunit.finance.project.entity.lexicon.PurchaseEnum;
import com.yuexunit.finance.project.service.AbnormalService;
import com.yuexunit.finance.project.service.ClaimAcceptanceService;
import com.yuexunit.finance.project.service.ClaimAssessmentService;
import com.yuexunit.finance.project.service.ClaimCorrectiveService;
import com.yuexunit.finance.project.service.ClaimCoverageService;
import com.yuexunit.finance.project.service.ClaimHandleService;
import com.yuexunit.finance.project.service.ClaimMaterialService;
import com.yuexunit.finance.project.service.ClaimReportCaseService;
import com.yuexunit.finance.project.service.ClaimService;
import com.yuexunit.finance.project.service.ClaimSettlementCoverageService;
import com.yuexunit.finance.project.service.ClaimSettlementService;
import com.yuexunit.finance.project.service.ClaimSurveyService;
import com.yuexunit.finance.project.service.InsuranceService;
import com.yuexunit.inject.ComponentFactory;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
 * @ClassName: FinanceClaimActionApiImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年12月10日 上午10:46:02
 */
@Implements(FinanceClaimActionApi.class)
public class FinanceClaimActionApiImpl extends FinanceBaseAction implements FinanceClaimActionApi {

	private InsuranceService insuranceService = ComponentFactory.loadClass(InsuranceService.class);

	private AbnormalService abnormalService = ComponentFactory.loadClass(AbnormalService.class);

	private ClaimService claimService = ComponentFactory.loadClass(ClaimService.class);

	private ClaimCoverageService claimCoverageService = ComponentFactory.loadClass(ClaimCoverageService.class);

	private ClaimReportCaseService claimReportCaseService = ComponentFactory.loadClass(ClaimReportCaseService.class);

	private ClaimAcceptanceService claimAcceptanceService = ComponentFactory.loadClass(ClaimAcceptanceService.class);

	private ClaimAssessmentService claimAssessmentService = ComponentFactory.loadClass(ClaimAssessmentService.class);

	private ClaimCorrectiveService claimCorrectiveService = ComponentFactory.loadClass(ClaimCorrectiveService.class);

	private ClaimHandleService claimHandleService = ComponentFactory.loadClass(ClaimHandleService.class);

	private ClaimMaterialService claimMaterialService = ComponentFactory.loadClass(ClaimMaterialService.class);

	private ClaimSettlementService claimSettlementService = ComponentFactory.loadClass(ClaimSettlementService.class);

	private ClaimSettlementCoverageService claimSettlementCoverageService = ComponentFactory.loadClass(ClaimSettlementCoverageService.class);

	private ClaimSurveyService claimSurveyService = ComponentFactory.loadClass(ClaimSurveyService.class);

	private boolean direct = BooleanUtils.toBoolean(ConfigPropertites.getProperties("claim.authenticat.direct", "true"));

	@Transactional
	@Override
	public String createClaim(ClaimParams params) {
		AbnormalEntity abnormal = abnormalService.inquireAbnormal(params.getAbnormalId());

		ClaimEntity claim = FinanceClaimCastor.fromClaim(params);
		claim.setAbnormalNumber(abnormal.getAbnormalNumber());
		Long claimId = claimService.createClaim(claim);

		abnormal.setClaimId(claimId);
		abnormalService.renovateAbnormal(abnormal);

		List<ClaimCoverageEntity> claimCoverages = FinanceClaimCastor.fromClaim(claim, params);
		for (ClaimCoverageEntity claimCoverage : claimCoverages) {
			claimCoverageService.createClaimCoverage(claimCoverage);
		}
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(abnormal.getFinanceId()), "融资理赔", "exception.claim", claim.getFinanceNumber(), DateUtils.getCurrentLinkedDateTime(), claim.getClaimNumber());
		return claimId.toString();
	}

	@Transactional
	@Override
	public void updateClaim(Long claimId, String claimDate, String claimRemark, Long[] claimCoverageId, BigDecimal[] claimAmount) {
		ClaimEntity persist = claimService.inquireClaim(claimId);
		persist.setClaimDate(DateUtil.parseDateInt(claimDate));
		persist.setClaimRemark(claimRemark);
		claimService.renovateClaim(persist);
		for (int i = 0; i < claimCoverageId.length; i++) {
			ClaimCoverageEntity claimCoverage = claimCoverageService.inquireClaimCoverage(claimCoverageId[i]);
			claimCoverage.setClaimAmount(claimAmount[i]);
			claimCoverageService.renovateClaimCoverage(claimCoverage);
		}
	}

	@Transactional
	@Override
	public void closeClaim(Long claimId, Integer windupReson, String windupRemark) {
		ClaimEntity persist = claimService.inquireClaim(claimId);
		if (ClaimStateEnum.CLAIM != persist.getClaimState()) {
			throw new BusinessException("异常理赔已经结束");
		}
		persist.setClaimState(ClaimStateEnum.CLOSED);
		persist.setWindupRemark(windupRemark);
		persist.setWindupReson(windupReson);
		claimService.renovateClaim(persist);
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(persist.getFinanceId()), "融资理赔", "exception.claim.closed", persist.getClaimNumber(), DateUtils.getCurrentLinkedDateTime());
	}

	@Transactional
	@Override
	public void finishedClaim(Long claimId, Integer windupReson, String windupRemark) {
		ClaimEntity persist = claimService.inquireClaim(claimId);
		if (ClaimStateEnum.CLAIM != persist.getClaimState()) {
			throw new BusinessException("异常理赔已经结束");
		}
		persist.setClaimState(ClaimStateEnum.FINISHED);
		persist.setWindupRemark(windupRemark);
		persist.setWindupReson(windupReson);
		claimService.renovateClaim(persist);
		// 发送消息
		FinanceLetterBlockingQueue.putEnterpriseExceptionLetter(getFinanceEnterpriseId(persist.getFinanceId()), "融资理赔", "exception.claim.finished", persist.getClaimNumber(), DateUtils.getCurrentLinkedDateTime());
	}

	@Transactional
	@Override
	public String createClaimReportCase(ClaimReportCase params) {
		ClaimReportCaseEntity entity = new ClaimReportCaseEntity();
		BeanUtils.copyProperties(params, entity);
		confirmAuthenticat(entity, direct);
		claimReportCaseService.createClaimReportCase(entity);
		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setReportCreateDateTime(DateUtil.now());
		if (!direct) {
			claim.setReportAuthenticat(claim.getReportAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getReportCaseId().toString();
	}

	@Transactional
	@Override
	public void consentClaimReportCase(Long reportCaseId) {
		ClaimReportCaseEntity entity = claimReportCaseService.inquireClaimReportCase(reportCaseId);
		confirmAuthenticat(entity);
		claimReportCaseService.renovateClaimReportCase(entity);
		if (!direct) {
			ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
			claim.setReportAuthenticat(claim.getReportAuthenticat() - 1);
			claimService.renovateClaim(claim);
		}
	}

	@Override
	public ClaimReportCaseDetail inquireClaimReportCase(Long reportCaseId) {
		ClaimReportCaseEntity entity = claimReportCaseService.inquireClaimReportCase(reportCaseId);
		return FinanceClaimCastor.toClaimReportCaseDetail(entity);
	}

	@Transactional
	@Override
	public String createClaimMaterial(ClaimMaterial params) {
		ClaimMaterialEntity entity = new ClaimMaterialEntity();
		BeanUtils.copyProperties(params, entity);
		confirmAuthenticat(entity, direct);
		claimMaterialService.createClaimMaterial(entity);
		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setMaterialCreateDateTime(DateUtil.now());
		if (!direct) {
			claim.setMaterialAuthenticat(claim.getMaterialAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getClaimMaterialId().toString();
	}

	@Transactional
	@Override
	public void consentClaimMaterial(Long claimMaterialId) {
		ClaimMaterialEntity entity = claimMaterialService.inquireClaimMaterial(claimMaterialId);
		confirmAuthenticat(entity);
		claimMaterialService.renovateClaimMaterial(entity);
		if (!direct) {
			ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
			claim.setMaterialAuthenticat(claim.getMaterialAuthenticat() - 1);
			claimService.renovateClaim(claim);
		}
	}

	@Override
	public ClaimMaterialDetail inquireClaimMaterial(Long claimMaterialId) {
		ClaimMaterialEntity entity = claimMaterialService.inquireClaimMaterial(claimMaterialId);
		return FinanceClaimCastor.toClaimMaterialDetail(entity);
	}

	@Transactional
	@Override
	public String createClaimAcceptance(ClaimAcceptance params) {
		ClaimAcceptanceEntity entity = new ClaimAcceptanceEntity();
		BeanUtils.copyProperties(params, entity);
		confirmAuthenticat(entity, direct);
		claimAcceptanceService.createClaimAcceptance(entity);

		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setAcceptanceCreateDateTime(DateUtil.now());
		if (!direct) {
			claim.setAcceptanceAuthenticat(claim.getAcceptanceAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getClaimAcceptanceId().toString();
	}

	@Transactional
	@Override
	public void consentClaimAcceptance(Long claimAcceptanceId) {
		ClaimAcceptanceEntity entity = claimAcceptanceService.inquireClaimAcceptance(claimAcceptanceId);
		confirmAuthenticat(entity);
		claimAcceptanceService.renovateClaimAcceptance(entity);

		if (!direct) {
			ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
			claim.setAcceptanceAuthenticat(claim.getAcceptanceAuthenticat() - 1);
			claimService.renovateClaim(claim);
		}
	}

	@Override
	public ClaimAcceptanceDetail inquireClaimAcceptance(Long claimAcceptanceId) {
		ClaimAcceptanceEntity entity = claimAcceptanceService.inquireClaimAcceptance(claimAcceptanceId);
		return FinanceClaimCastor.toClaimAcceptanceDetail(entity);
	}

	@Transactional
	@Override
	public String createClaimSurvey(ClaimSurvey params) {
		ClaimSurveyEntity entity = new ClaimSurveyEntity();
		BeanUtils.copyProperties(params, entity);
		confirmAuthenticat(entity, direct);
		claimSurveyService.createClaimSurvey(entity);

		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setSurveyCreateDateTime(DateUtil.now());
		if (!direct) {
			claim.setSurveyAuthenticat(claim.getSurveyAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getClaimSurveyId().toString();
	}

	@Transactional
	@Override
	public void consentClaimSurvey(Long claimSurveyId) {
		ClaimSurveyEntity entity = claimSurveyService.inquireClaimSurvey(claimSurveyId);
		confirmAuthenticat(entity);
		claimSurveyService.renovateClaimSurvey(entity);

		if (!direct) {
			ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
			claim.setSurveyAuthenticat(claim.getSurveyAuthenticat() - 1);
			claimService.renovateClaim(claim);
		}
	}

	@Override
	public ClaimSurveyDetail inquireClaimSurvey(Long claimSurveyId) {
		ClaimSurveyEntity entity = claimSurveyService.inquireClaimSurvey(claimSurveyId);
		return FinanceClaimCastor.toClaimSurveyDetail(entity);
	}

	@Transactional
	@Override
	public String createClaimAssessment(ClaimAssessment params) {
		ClaimAssessmentEntity entity = new ClaimAssessmentEntity();
		BeanUtils.copyProperties(params, entity);
		confirmAuthenticat(entity, direct);
		claimAssessmentService.createClaimAssessment(entity);

		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setAssessmentCreateDateTime(DateUtil.now());
		if (!direct) {
			claim.setAssessmentAuthenticat(claim.getAssessmentAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getClaimAssessmentId().toString();
	}

	@Transactional
	@Override
	public void consentClaimAssessment(Long claimAssessmentId) {
		ClaimAssessmentEntity entity = claimAssessmentService.inquireClaimAssessment(claimAssessmentId);
		confirmAuthenticat(entity);
		claimAssessmentService.renovateClaimAssessment(entity);

		if (!direct) {
			ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
			claim.setAssessmentAuthenticat(claim.getAssessmentAuthenticat() - 1);
			claimService.renovateClaim(claim);
		}
	}

	@Override
	public ClaimAssessmentDetail inquireClaimAssessment(Long claimAssessmentId) {
		ClaimAssessmentEntity entity = claimAssessmentService.inquireClaimAssessment(claimAssessmentId);
		return FinanceClaimCastor.toClaimAssessmentDetail(entity);
	}

	@Transactional
	@Override
	public String createClaimHandle(ClaimHandle params) {
		ClaimHandleEntity entity = new ClaimHandleEntity();
		BeanUtils.copyProperties(params, entity);
		confirmAuthenticat(entity, direct);
		claimHandleService.createClaimHandle(entity);

		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setHandleCreateDateTime(DateUtil.now());
		if (!direct) {
			claim.setHandleAuthenticat(claim.getHandleAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getClaimHandleId().toString();
	}

	@Transactional
	@Override
	public void consentClaimHandle(Long claimHandleId) {
		ClaimHandleEntity entity = claimHandleService.inquireClaimHandle(claimHandleId);
		confirmAuthenticat(entity);
		claimHandleService.renovateClaimHandle(entity);

		if (!direct) {
			ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
			claim.setHandleAuthenticat(claim.getHandleAuthenticat() - 1);
			claimService.renovateClaim(claim);
		}
	}

	@Override
	public ClaimHandleDetail inquireClaimHandle(Long claimHandleId) {
		ClaimHandleEntity entity = claimHandleService.inquireClaimHandle(claimHandleId);
		return FinanceClaimCastor.toClaimHandleDetail(entity);
	}

	private void caculateClaimSettlement(ClaimEntity claim, ClaimSettlementEntity settlement, List<ClaimSettlementCoverageEntity> settlementCoverages) {
		for (ClaimSettlementCoverageEntity settlementCoverage : settlementCoverages) {
			// 合计入索赔险种信息中
			ClaimCoverageEntity claimCoverage = claimCoverageService.inquireClaimCoverage(settlementCoverage.getClaimCoverageId());
			claimCoverage.setIndemnityAmount(claimCoverage.getIndemnityAmount().add(settlementCoverage.getIndemnityAmount()));
			claimCoverage.setIndemnityDate(settlementCoverage.getIndemnityDate());
			claimCoverageService.renovateClaimCoverage(claimCoverage);
		}
		// 合计如索赔单中
		claim.setIndemnityAmount(claim.getIndemnityAmount().add(settlement.getSettlementAmount()));

		InsuranceEntity insurance = insuranceService.inquireInsuranceEntity(claim.getInsuranceId());
		if (PurchaseEnum.AGENT == insurance.getPurchase()) { // 委托代理(平台付款单)
			// 保险公司->平台
			FinanceMoneyStatementEntity statement = FinanceLoanCastor.fromPlatformAgentInsuranceClaim(insurance, claim, settlement);
			financeMoneyStatementService.createFinanceMoneyStatement(statement);
			// 平台->投保人
			statement = FinanceLoanCastor.fromEnterpriseAgentInsuranceClaim(insurance, claim, settlement);
			financeMoneyStatementService.createFinanceMoneyStatement(statement);
		} else {
			// 保险公司->投保人
			FinanceMoneyStatementEntity statement = FinanceLoanCastor.fromEnterpriseInsuranceClaim(insurance, claim, settlement);
			financeMoneyStatementService.createFinanceMoneyStatement(statement);
		}
	}

	@Transactional
	@Override
	public String createClaimSettlement(ClaimSettlementParams params) {
		ClaimSettlementEntity entity = new ClaimSettlementEntity();
		BeanUtils.copyProperties(params, entity);
		entity.setSettlementAmount(BigDecimal.ZERO);
		confirmAuthenticat(entity, direct);
		claimSettlementService.createClaimSettlement(entity);
		List<ClaimSettlementCoverageEntity> settlementCoverages = new ArrayList<>();
		for (int i = 0; i < params.getInsuranceCoverageId().length; i++) {
			ClaimCoverageEntity claimCoverage = claimCoverageService.inquireClaimCoverage(CollectionUtils.getArrayIndexValue(params.getInsuranceCoverageId(), i), params.getClaimId());
			ClaimSettlementCoverageEntity csce = new ClaimSettlementCoverageEntity();
			csce.setInsuranceCoverageId(claimCoverage.getInsuranceCoverageId());
			csce.setClaimCoverageId(claimCoverage.getClaimCoverageId());
			csce.setClaimSettlementId(entity.getClaimSettlementId());
			csce.setIndemnityAmount(CollectionUtils.getArrayIndexValue(params.getIndemnityAmount(), i));
			csce.setIndemnityDate(CollectionUtils.getArrayIndexValue(params.getIndemnityDate(), i));
			claimSettlementCoverageService.createClaimSettlementCoverage(csce);
			settlementCoverages.add(csce);
			// 合计入理赔阶段信息中
			entity.setSettlementAmount(entity.getSettlementAmount().add(csce.getIndemnityAmount()));
		}
		claimSettlementService.renovateClaimSettlement(entity);
		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setSettlementCreateDateTime(DateUtil.now());
		if (direct) {
			caculateClaimSettlement(claim, entity, settlementCoverages);
		} else {
			claim.setSettlementAuthenticat(claim.getCorrectiveAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getClaimSettlementId().toString();

	}

	@Transactional
	@Override
	public void consentClaimSettlement(Long claimSettlementId) {
		ClaimSettlementEntity entity = claimSettlementService.inquireClaimSettlement(claimSettlementId);
		confirmAuthenticat(entity);
		List<ClaimSettlementCoverageEntity> settlementCoverages = claimSettlementCoverageService.inquireClaimSettlementCoverageList(entity.getClaimSettlementId());
		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setSettlementAuthenticat(claim.getCorrectiveAuthenticat() - 1);
		caculateClaimSettlement(claim, entity, settlementCoverages);
		claimSettlementService.renovateClaimSettlement(entity);
		claimService.renovateClaim(claim);
	}

	@Override
	public ClaimSettlementDetail inquireClaimSettlement(Long claimSettlementId) {
		ClaimSettlementEntity entity = claimSettlementService.inquireClaimSettlement(claimSettlementId);
		return FinanceClaimCastor.toClaimSettlementDetail(entity);
	}

	@Transactional
	@Override
	public String createClaimCorrective(ClaimCorrective params) {
		ClaimCorrectiveEntity entity = new ClaimCorrectiveEntity();
		BeanUtils.copyProperties(params, entity);
		confirmAuthenticat(entity, direct);
		claimCorrectiveService.createClaimCorrective(entity);

		ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
		claim.setCorrectiveCreateDateTime(DateUtil.now());
		if (!direct) {
			claim.setCorrectiveAuthenticat(claim.getCorrectiveAuthenticat() + 1);
		}
		claimService.renovateClaim(claim);
		return entity.getClaimCorrectiveId().toString();
	}

	@Transactional
	@Override
	public void consentClaimCorrective(Long claimCorrectiveId) {
		ClaimCorrectiveEntity entity = claimCorrectiveService.inquireClaimCorrective(claimCorrectiveId);
		confirmAuthenticat(entity);
		claimCorrectiveService.renovateClaimCorrective(entity);

		if (!direct) {
			ClaimEntity claim = claimService.inquireClaim(entity.getClaimId());
			claim.setCorrectiveAuthenticat(claim.getCorrectiveAuthenticat() - 1);
			claimService.renovateClaim(claim);
		}
	}

	@Override
	public ClaimCorrectiveDetail inquireClaimCorrective(Long claimCorrectiveId) {
		ClaimCorrectiveEntity entity = claimCorrectiveService.inquireClaimCorrective(claimCorrectiveId);
		return FinanceClaimCastor.toClaimCorrectiveDetail(entity);
	}

	@Override
	public ClaimDetail inquireClaimDetail(Long claimId) {
		ClaimEntity entity = claimService.inquireClaim(claimId);
		return FinanceClaimCastor.toClaimDetail(entity);
	}

	@Override
	public PageList<ClaimLineInfo> inquireClaimPageList(Long financeId, String dateBegin, String dateEnd, String claimNumber, Integer abnormalState, String insuranceCompany, Integer claimProcess, Integer claimState, PageCriteria page) {
		Integer beginDate = DateUtil.parseDateInt(dateBegin);
		Integer endDate = DateUtil.parseDateInt(dateEnd);
		AbnormalStateEnum _state = AbnormalStateEnum.valueOf(abnormalState);
		PageList<ClaimEntity> pages = claimService.inquireClaimPageList(financeId, beginDate, endDate, claimNumber, _state, insuranceCompany, claimProcess, claimState, page);
		PageList<ClaimLineInfo> results = new PageList<>(page, pages.getTotalRecordCount());
		for (ClaimEntity dae : pages) {
			results.add(FinanceClaimCastor.toClaimLineInfo(dae));
		}
		return results;
	}

}
